/**
 * Created by zrb on 2016/5/6.
 */
;(function(w, a){
    var params = {
        loading:'处理中，请稍后...'
    };
    var utils={
		isFunction:function(fun){
		    return Object.prototype.toString.call(fun) === "[object Function]";
    	},
    	isEmpty:function(text){
    		return undefined==text||null==text||""==text;
    	}	
    };
    var Stem = function(){};
    Stem.prototype={
    	close:function(index){
        	a.close(index);
        },
        closeAll:function(){
        	a.closeAll();
        },
        loading:function(msg){
            return a.msg(utils.isEmpty(msg)?params.loading:msg,{icon: 16,shade: [0.5, '#393D49'],time:0});
        },
        info:function(msg,callback){
        	return a.alert(msg, {icon: 1},function(index){
        		if(undefined!=callback&&null!=callback&&utils.isFunction(callback)){
        			callback.call(callback.arguments);
  	    	  	}
        		a.close(index);
        	});
        },
        warn:function(msg,callback){
        	return a.alert(msg, {icon: 0},function(index){
        		if(undefined!=callback&&null!=callback&&utils.isFunction(callback)){
        			callback.call(callback.arguments);
  	    	  	}
        		a.close(index);
        	});
        },
        tip:function(msg, idSel){
        	return a.tips(msg, idSel);
        },
        confirm:function(msg,title,ok,cancel){
        	if(utils.isEmpty(title)){
        		title="提示信息";
        	}
        	a.confirm(msg, {icon: 1, title:title}, function(index){
	    	  if(undefined!=ok&&null!=ok&&utils.isFunction(ok)){
	    		  ok.call(ok.arguments);
	    	  }
    		  a.close(index);
    		},
    		function(index){
    		  if(undefined!=cancel&&null!=cancel&&utils.isFunction(cancel)){
    			cancel.call(cancel.arguments);
    		  }
    		  a.close(index);
    		});
        },
        msg:function(msg,callback){
        	a.msg(msg, function(){
        		if(undefined!=callback&&null!=callback&&utils.isFunction(callback)){
        			callback.call(callback.arguments);
        		}
        	});
        },
        iframe:function(title,url,area){
        	if(undefined==area||null==area||""==area){
        		area = ['380px', '80%'];
        	}
        	return a.open({
    		  type: 2,
    		  title: title,
    		  shadeClose: false,
    		  scrollbar:false,
    		  shade: 0.8,
    		  area: area,
    		  content: url
    		}); 
        }
    };

    w.stem=new Stem();
    w.utils = utils;
})(window,layer);